package qr.server;

import qr.server.admin.AddLocationScreen;
import qr.server.admin.ApplicationWindow;
import qr.server.admin.CreateGameScreen;
import qr.server.admin.HomeScreen;
import qr.server.admin.ManageLeaderboardScreen;

import java.io.IOException;
import java.net.URI;

import javax.ws.rs.core.UriBuilder;

import org.glassfish.grizzly.http.server.HttpServer;

import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
/**
 * Launches administrative interface.
 * 
 * @author Brian
 * 
 */
public class Main {
	
	private static URI getBaseURI() { 
	
		return UriBuilder.fromUri("http://129.21.91.97/").port(8080).build();
	}
	
	private static final URI baseURI = getBaseURI(); 
	
	protected static HttpServer startHttpServer() throws IOException { 
		System.out.println("Starting Grizzly Web Server...");
		ResourceConfig mainRC = new PackagesResourceConfig("qr.server");
		return GrizzlyServerFactory.createHttpServer(baseURI, mainRC);
	}
	
	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws IOException {
		new ApplicationWindow()
				.include(
						HomeScreen.class,
						AddLocationScreen.class,
						CreateGameScreen.class,
						ManageLeaderboardScreen.class)
				.start("HomeScreen");
		
		//Start Grizzly Web Server 
		HttpServer server = startHttpServer(); 
		System.out.println("RIT QR Code Game Jersey Application REST Server Started");
		System.in.read();
		server.stop();
	}
}